#include <iostream>
#include <unordered_map>
using namespace std;

class Solution 
{
public:
    bool checkAlmostEquivalent(string word1, string word2) 
    {
        unordered_map<char, int> ump;
        for (auto l : word1)
        {
            ump[l]++;
        }
        for (auto j : word2)
        {
            ump[j]--;
        }

        for (int i = 0; i < ump.size(); i++)
        {
            if (ump[i] > 3 || ump[i] < -3)
            {
                return false;
            }
        }

        return true;
    }
};

int main()
{
    string word1{ "abcdeef" };
    string word2{ "abaaacc" };

    Solution xz;

    bool b = xz.checkAlmostEquivalent(word1, word2);
    if (b)
    {
        cout << "true" << endl;
    }
    else
        cout << "false" << endl;

	return 0;
}